<?php
if ($lang == 0) {
	$sql1 = sprintf ( "select URL,id,vi_name as name from tblmenu where section_id=0 order by `order` " );
	$sql2 = sprintf ( "select URL,id,vi_name as name,section_id,parent_id from tblmenu where section_id<>0" );
	$sql3 = sprintf ( "select URL,id,vi_name  as name,parent_id from tblmenu where section_id=-1 " );
} 

else {
	$sql1 = sprintf ( "select URL,id,en_name as name from tblmenu where section_id=0 order by `order`" );
	$sql2 = sprintf ( "select URL,id,en_name  as name,section_id,parent_id   from tblmenu where section_id<>0  " );
	$sql3 = sprintf ( "select URL,id,en_name  as name,parent_id  from tblmenu where section_id=-1 " );
}
$Menus1 = mysql_query ( $sql1 ) or die ( mysql_error () );
$Menus2 = mysql_query ( $sql2 ) or die ( mysql_error () );
$Menus3 = mysql_query ( $sql3 ) or die ( mysql_error () );
?>
<div id="menu">
	<ul>
    	<?php
		while ( $menu1 = mysql_fetch_assoc ( $Menus1 ) ) {
			echo "<li>";
			echo "<a";
			if ($menu1 ['URL'] != '') echo " href='" . $menu1 ['URL'] . "'";
			echo ">" . $menu1 ['name'] . "</a>";
		?>
	 	<span class="line"></span>
		<?php
		$childsection = 0;
		while ( $menu2 = mysql_fetch_assoc ( $Menus2 ) ) {												
			if ($menu2 ['parent_id'] == $menu1 ['id']) {
				
				if ($childsection == 0) {
					echo "<div class='arrow'></div>";
					echo "<ul>";
					$childsection = 1;
				}
				
				echo "<li>";
				echo "<a href='/view/s/".$menu2['section_id']."'>".$menu2 ['name'] . "</a>";
				//if ($menu2 ['URL'] != '') echo " href='" . $menu2 ['URL'] . "'";
				//echo ">" . $menu2 ['name'] . "</a>";
				$childend = 0;
				while ( $menu3 = mysql_fetch_assoc ( $Menus3 ) ) {
																					
					if ($menu2 ['id'] == $menu3 ['parent_id']) {
						if ($childend == 0) {
							echo "<div class='arrow'></div>";
							echo "<ul>";
							$childend = 1;
						}
						echo "<li><a href='" . $menu3 ['URL'] . "'>" . $menu3 ['name'] . "</a></li>";
					}
																			
				}
				if (mysql_num_rows($Menus3) > 0 ) mysql_data_seek ( $Menus3, 0 );
				if ($childend == 1) echo "</ul>";
				echo "</li>";
			}
																	
		}
		if (mysql_num_rows($Menus2) > 0 ) mysql_data_seek ( $Menus2, 0 );
		if ($childsection == 1) echo "</ul>";
		echo "</li>";
	}
	?>
	</ul>

</div>